package com.ycp.erp.warehouse.ui.activity;

import android.annotation.SuppressLint;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jakewharton.rxbinding2.view.RxView;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.utils.KeyboardUtil;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.dialog.AutoDialogHelper;
import com.one.common.view.multitytype.MultiTypeAdapter;
import com.one.common.view.widget.MyTitleBar;
import com.one.common.view.widget.ScrollLinearLayoutManager;
import com.one.common.view.widget.SwitchView;
import com.ycp.erp.R;
import com.ycp.erp.warehouse.model.bean.ProcurementWarehouse;
import com.ycp.erp.warehouse.ui.binder.ConfirmPWarehouseBinder;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * Class Des:采购入库详情
 * Created by bjh on 2021/9/8.
 */
@Route(path = RouterPath.PROTURE_ENTER_WAREHOUSE)
public class ProcureEnterWarehouseActivity extends BaseActivity {
    @BindView(R.id.tvSelectWareHouse)
    TextView tvSelectWareHouse;
    @BindView(R.id.rlSelectWareHouse)
    RelativeLayout rlSelectWareHouse;
    @BindView(R.id.tvSelectSupplier)
    TextView tvSelectSupplier;
    @BindView(R.id.rlSelectSupplier)
    RelativeLayout rlSelectSupplier;
    @BindView(R.id.tvSelectPDate)
    TextView tvSelectPDate;
    @BindView(R.id.rlSelectPDate)
    RelativeLayout rlSelectPDate;
    @BindView(R.id.tvSelectPTime)
    TextView tvSelectPTime;
    @BindView(R.id.rlSelectPTime)
    RelativeLayout rlSelectPTime;
    @BindView(R.id.tvTotalPrice)
    TextView tvTotalPrice;
    @BindView(R.id.rlTotalPrice)
    RelativeLayout rlTotalPrice;
    @BindView(R.id.tvDiscountPrice)
    TextView tvDiscountPrice;
    @BindView(R.id.rlDiscountPrice)
    RelativeLayout rlDiscountPrice;
    @BindView(R.id.tvPaidPrice)
    TextView tvPaidPrice;
    @BindView(R.id.rlTotalPricePayable)
    RelativeLayout rlTotalPricePayable;
    @BindView(R.id.swCredit)
    SwitchView swCredit;
    @BindView(R.id.rlCredit)
    RelativeLayout rlCredit;
    @BindView(R.id.tvAddRemarks)
    TextView tvAddRemarks;
    @BindView(R.id.tvRemarks)
    TextView tvRemarks;
    @BindView(R.id.rcv)
    RecyclerView rcv;
    @BindView(R.id.nsc)
    NestedScrollView nsc;
    @BindView(R.id.tvDownload)
    TextView tvDownload;
    @BindView(R.id.tvPrint)
    TextView tvPrint;
    @BindView(R.id.rlBottom)
    RelativeLayout rlBottom;
    private MultiTypeAdapter adapter;

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("采购入库详情").hideLine();
    }

    @SuppressLint("CheckResult")
    @Override
    public void initData() {
        super.initData();
        ScrollLinearLayoutManager scrollLinearLayoutManager = new ScrollLinearLayoutManager(getContext());
        scrollLinearLayoutManager.setScrollEnable(false);
        rcv.setLayoutManager(scrollLinearLayoutManager);
        adapter = new MultiTypeAdapter();
        ConfirmPWarehouseBinder mBinder = new ConfirmPWarehouseBinder();
        adapter.register(ProcurementWarehouse.class, mBinder);
        rcv.setAdapter(adapter);
        adapter.setItems(getData());
        adapter.notifyDataSetChanged();

        RxView.clicks(tvPrint).throttleFirst(500,TimeUnit.MILLISECONDS).subscribe(o -> {
            new KeyboardUtil(mContext).hideSoftInputFromWindow(myRxActivity);
            RouterManager.getInstance().go(RouterPath.SELECT_PRINTER);

        });
        RxView.clicks(tvDownload).throttleFirst(500,TimeUnit.MILLISECONDS).subscribe(o->{
            new KeyboardUtil(mContext).hideSoftInputFromWindow(myRxActivity);
            AutoDialogHelper.showContent(getContext(), "提示", "确认下载入库单？", "取消", "确定", () -> {

            }, () -> {

            });
        });
    }

    private String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    /**
     * 模拟数据
     *
     * @return
     */
    private ArrayList<ProcurementWarehouse> getData() {
        ArrayList<ProcurementWarehouse> procurementWarehouses = new ArrayList<>();
        ProcurementWarehouse procurementWarehouse = new ProcurementWarehouse();
        procurementWarehouse.setGoodsName("测试");
        procurementWarehouse.setGoodsDesc("测试描述");
        procurementWarehouse.setGoodsNum(0);
        procurementWarehouse.setGoodsPrice("100");
        procurementWarehouses.add(procurementWarehouse);
        ProcurementWarehouse procurementWarehouse1 = new ProcurementWarehouse();
        procurementWarehouse1.setGoodsName("测试");
        procurementWarehouse1.setGoodsDesc("测试描述");
        procurementWarehouse1.setGoodsNum(0);
        procurementWarehouse1.setGoodsPrice("100");
        procurementWarehouses.add(procurementWarehouse1);
        ProcurementWarehouse procurementWarehouse2 = new ProcurementWarehouse();
        procurementWarehouse2.setGoodsName("测试");
        procurementWarehouse2.setGoodsDesc("测试描述");
        procurementWarehouse2.setGoodsNum(0);
        procurementWarehouse2.setGoodsPrice("100");
        procurementWarehouses.add(procurementWarehouse2);
        return procurementWarehouses;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_proture_enter_warehouse;
    }
}
